package com.sc.servlet.admin;

import com.alibaba.fastjson.JSONObject;
import com.sc.pojo.User;
import com.sc.services.FieldServices;
import com.sc.services.UserServices;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @description: 管理员登陆后向session发送请求获取登录的管理员信息
 * @author: sc
 * @create: 2023-01-05 22:55
 **/
@WebServlet("/getLoginAdmin")
public class getLoginAdminServlet extends HttpServlet {
private UserServices  userServices = new UserServices();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
       String adminname = userServices.selectAdminName((String) session.getAttribute("adminname"));


        String jsonString = JSONObject.toJSONString(adminname);
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(jsonString);



    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}